Home:ALL Converter>jQuery code that doesn`t work on WordPress

jQuery code that doesn`t work on WordPress

Ask Time:2014-04-24T23:59:28         Author:ThemesCreator

Json Formatter

I have a contact form that I submit via jQuery. It works perfectly on HTML/PHP/JS template, but when I use it on a WordPress it doesn't work fine.

The form is submited, but the jquery code inside the submit function is like doesn't exit. It doesn't retrieve any error but the loader doesn`t appear and jquery validation doesn't occurs:

<form method="post" action="<?php echo get_template_directory_uri() . '/templates/contact.php' ?>" name="contactform" id="contactform">
                <div class="col-sm-6">
                    <fieldset>
                        <input name="name" type="text" id="name" size="30" value="" placeholder="Name" />
                        <br />
                        <input name="email" type="text" id="email" size="30" value="" placeholder="Email" />
                        <br />
                        <input name="phone" type="text" id="phone" size="30" value="" placeholder="Phone" />
                        <br />
                    </fieldset>
                </div>
                <div class="col-sm-6">
                    <fieldset>
                        <textarea name="comments" cols="40" rows="8" id="comments" placeholder="Message"></textarea>
                        <button type="submit" class="btn btn-green-border btn-lg" id="submit" value="submit">Send Message</button>
                    </fieldset>
                </div>
            </form>

This is the jQuery:

// Send email 
    jQuery('#contactform').submit(function ($) {

        var action = $(this).attr('action');

        $("#message").slideUp(750, function () {
            $('#message').hide();

            $('#submit')
                .after('<img src="images/loader.gif" class="loader" />')
                .attr('disabled', 'disabled');

            $.post(action, {
                    name: $('#name').val(),
                    email: $('#email').val(),
                    phone: $('#phone').val(),
                    comments: $('#comments').val(),
                    verify: $('#verify').val()
                },
                function (data) {
                    document.getElementById('message').innerHTML = data;
                    $('#message').slideDown('slow');
                    $('#contactform img.loader').fadeOut('slow', function () {
                        $(this).remove()
                    });
                    $('#submit').removeAttr('disabled');
                    if (data.match('success') != null) $('#contactform').slideUp('slow');

                }
            );

        });

        return false;

    });

What can be the problem?

Author:ThemesCreator,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23274007/jquery-code-that-doesnt-work-on-wordpress
mackth :

jQuery('#contactform').submit(function ($) {\n\n\nTry removing the $ in function()\n\n jQuery('#contactform').submit(function () {\n",
2014-04-24T16:02:52
Reece :

Your Wordpress installation could be using a version of jQuery that is incompatible with your code, try including a newer version",
2014-04-24T16:11:27
yy